<?php
namespace app\common\model;

use think\Model;

/**  YSF
 *   优惠券 模型
 *   Date: 2018/11/30
 * Class CouponModel
 * @package app\common\model
 */
class CouponModel extends Model
{
    // 表名
    protected $name = 'coupon';

    // 单表数量查询
    public function getCount($where=[])
    {
        $result = $this->where($where)
                    ->count();
        return $result;
    }

    // 连表列表查询
    public function getJoinAll($where=[],$join=[],$field='*',$page=1,$pageSize=999,$order='')
    {
        $result = $this->alias('a')
                ->join($join)
                ->where($where)
                ->field($field)
                ->page($page, $pageSize)
                ->order($order)
                ->select();
        return $result;
    }

    // 连表数量查询
    public function getJoinCount($where=[],$join=[])
    {
        $result = $this->alias('a')
                    ->join($join)
                    ->where($where)
                    ->count();
        return $result;
    }

    // 删除
    public function del($where=[])
    {
        $result = $this->where($where)->delete();
        return $result;
    }

    // 连表单条查询
    public function getJoinOne($where=[],$join=[],$field='*')
    {
        $result = $this->alias('a')
                ->join($join)
                ->where($where)
                ->field($field)
                ->find();
        return $result;
    }

}